import api from "../../api/index.js";
Page({
  data: {
    minDate: new Date().getTime(),
    maxDate: new Date().getTime(),
    formatter(day) {
      return day;
    },
  },
  onLoad: function (options) {
    getApp().initLanguage(this)
    wx.setNavigationBarTitle({
      title: this.data.$t.my.signDaily,
    })
    this.scoreSignLogs()
  },
  onShow: function () {

  },
  async scoreSignLogs() {
    api.signLogList(({
        data: {}
      }))
      .then((res) => {
        const dateOnlyArray = res.data.map(item => item.signDate);
        this.setData({
          scoreSignLogs: res.data,
          formatter(day) {
            const _log = res.data.find(ele => {
              const year = day.date.getYear() + 1900
              let month = day.date.getMonth() + 1
              month = month + ''
              if (month.length == 1) {
                month = '0' + month
              }
              let date = day.date.getDate() + ''
              if (date.length == 1) {
                date = '0' + date
              }
              return dateOnlyArray.indexOf(`${year}-${month}-${date}`) != -1
            })
            if (_log) {
              day.bottomInfo = '签到'
            }
            return day;
          }
        })
      })
  },
  async sign() {
    api.signLogAdd(({
      data: {}
    })).then((res)=>{
      this.scoreSignLogs()
    })
  },
})